use chrono::NaiveDateTime;

use super::{person::Person, role::Role};

// IAssociations 使用关联关系表， dentifiable 有 PersonRole::belongs_to函数调用
#[derive(Associations, Identifiable)]
#[diesel(belongs_to(Person, foreign_key = person_id))] // #[diesel(belongs_to(Person))]
#[diesel(belongs_to(Role, foreign_key = role_id))] // #[diesel(belongs_to(Role))]
#[diesel(table_name = crate::schema::persons_roles)]
pub struct PersonRole {
  pub id: i32,
  pub person_id: i32,
  pub role_id: i32,
  pub created_at: NaiveDateTime,
}

#[derive(Insertable)]
#[diesel(table_name = crate::schema::persons_roles)]
pub struct NewPersonRole {
  pub person_id: i32,
  pub role_id: i32,
}

#[derive(Queryable)]
#[diesel(table_name = crate::schema::persons_roles)]
pub struct UpdatePersonRole {
  // #[serde(skip_deserializing)]
  // pub id: i32,
  pub person_id: i32,
  pub role_id: i32,
  // #[serde(skip_deserializing)]
  // pub created_at: NaiveDateTime,
}
